//go:build wireinject

package startup

import (
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory"
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory/cache"
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory/dao"
	"gitee.com/chicken-c/go-learn/webook/internal/service"
	"gitee.com/chicken-c/go-learn/webook/internal/web"
	"gitee.com/chicken-c/go-learn/webook/internal/web/jwt"
	"gitee.com/chicken-c/go-learn/webook/ioc"
	"github.com/gin-gonic/gin"
	"github.com/google/wire"
)

func InitWebServer() *gin.Engine {
	wire.Build(
		//第三方依赖
		InitDB, InitRedis,
		InitLogger,

		//dao
		dao.NewUserDao,
		dao.NewGORMArticleDAO,

		//cache
		cache.NewRedisCodeCache, cache.NewUserCache,

		//repo
		repostiory.NewCachedUserRepository, repostiory.NewCachedCodeRepository,
		repostiory.NewCachedArticleRepostiory,

		//service
		ioc.InitSMSService,
		ioc.InitWechatService,
		service.NewuserService, service.NewcodeService,
		service.NewArticleService,

		//userHandle
		web.NewUserHandler,
		web.NewOAuto2WechatHandler,
		jwt.NewRedisJWTHandler,
		web.NewArticleHandler,

		//gin middleware
		GinMiddlewares, //需要传入redis.Cmdable
		//集合所有的中间件和handler注册路由
		InitServer, //需要传入[]gin.HandlerFunc 也就是我们的use()middleware
	)

	//返回值我们随便返回，wire只需要知道类型就行
	return gin.Default()
}
